import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class MarkdownBuilder extends Builder
{
    private String filename;
    private PrintWriter writer;
    @Override
    public void makeTitle(String title)
    {
        filename=title+".md";
        try {
            writer = new PrintWriter(new FileWriter(filename));  // 建立PrintWriter
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.println("# "+title+"\n");
    }

    @Override
    public void makeString(String str)
    {
        writer.println("- "+str+"\n");
    }

    @Override
    public void makeItems(String[] items)
    {
        for(int i=1;i<=items.length;i++)
        {
            writer.println(i+". "+items[i-1]+"\n");
        }
    }

    @Override
    public Object getResult()
    {
        writer.close();
        return filename;
    }
}
